import axios from "axios";
import Base64 from "crypto-js/enc-base64.js";
import AES from "crypto-js/aes.js";
import Utf8 from "crypto-js/enc-utf8.js";

const getTimetable = async () => {
  try {
      const response = await axios.get('https://api.remmody.ru/v2/timetable?next', {
    headers: {
      'Botkey': "7208c1d06c3e4d088a29a9cc2d87ee1b"
    },
  })
    let data = await response.data

    const key = Base64.parse("NGM5NjVlOWUyMWVlYjNhNTZhZWQ3YTQzNjg3NTc1MWU=");
    const iv = Base64.parse("MjljNzZlYjU0MjA1MTg0YQ==");

    const decrypted = AES.decrypt(data, key, { iv: iv });
    data = decrypted.toString(Utf8);
    return data
  }
  catch (error) {
    console.log(error)
  }
}

export default defineEventHandler((event) => {
  return getTimetable()
})
